package net.bolue.sysmng.entry;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class EntryUtil {

	public static <T>DbTable entryToTable(Class<T> entryClass){
		DbTable dbTable = new DbTable();
		String entryName = entryClass.getName();
		entryName = entryName.toUpperCase();
		dbTable.setTableName(entryName);
		Field[] fields = entryClass.getFields();
		List<DbColumn> columns = new ArrayList<DbColumn>();
		if(fields.length>0){
			for(int i=0;i<fields.length;i++){
				Field field = fields[i];
				String fieldName = field.getName();
				fieldName = fieldName.toUpperCase();
				DbColumn dbColumn = new DbColumn();
				dbColumn.setName(fieldName);
				columns.add(dbColumn);
			}
		}
		dbTable.setColumns(columns);
		return dbTable;
	}
}
